<?php

/**
 * calendrier form.
 *
 * @package    gesp
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class calendrierForm extends BasecalendrierForm {
	public function configure() {
		// redéfinition des widgets
		$this->setWidget('cal_prj_id', new sfWidgetFormInputHidden());
		$this->setWidget('cal_calpln_id', new sfWidgetFormInputHidden());
		$this->setWidget('cal_date', new DatePickerWidget(array('default' => date('d/m/Y'))));
		$this->setWidget('cal_heure_debut', new sfWidgetFormTime(array('minutes' => array(0 => '00', 15 => '15', 30 => '30', 45 => '45'), 'default' => '00:00')));
		$this->setWidget('cal_heure_fin', new sfWidgetFormTime(array('minutes' => array(0 => '00', 15 => '15', 30 => '30', 45 => '45'))));
		
		// modification des libellés
		$this->widgetSchema->setLabels(array(
			'cal_date' => 'Date',
			'cal_heure_debut' => 'Heure de début',
			'cal_heure_fin' => 'Heure de fin',
			'cal_libelle' => 'Libellé',
			'cal_description' => 'Description',
			'cal_alerte' => 'Alerte',
		));

		// redéfinition des validateurs
		$this->validatorSchema['cal_libelle']->setOption('required', true);
		$this->setValidator(
			'cal_date',
			new ValidatorDate(array(
				'required' => true,
				'date_format' => '/^(?P<day>\d+)\/(?P<month>\d+)(\/(?P<year>\d+))?/',
				),
				array(
				'bad_format' => "format de date invalide : dd/mm[/yyyy]",
				)
			)
		);
	}
	
	public function bind(array $taintedValues = null, array $taintedFiles = null) {
		if ($taintedValues['cal_heure_fin']['hour'] == '') {
			$taintedValues['cal_heure_fin']['minute'] = '';
		}
		if (isset($taintedValues['cal_alerte'])) {
			$taintedValues['cal_actif'] = $taintedValues['cal_alerte'];
		}
		return parent::bind($taintedValues, $taintedFiles);
	}
}
